package server.main.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import server.main.config.cache.MybatisPlusRedisCache;
import server.main.pojo.Permission;
import server.main.pojo.Role;

import java.util.List;

/**
 * @auther MingHsZzz
 * @Date 2022/9/7-12:33
 */



@Mapper
@CacheNamespace(implementation = MybatisPlusRedisCache.class)
public interface RoleMapper extends BaseMapper<Role> {


    /**
     * 获取用户的角色信息
     * @param jobnum 工号
     * @return Role对象列表
     */
    @Select("select role.id,role.`name`,role.nameZh,role.rdescribe from account_role as ar\n" +
            "LEFT JOIN role ON ar.role_id = role.id\n" +
            "WHERE server_account_jobnum = #{jobnum}")
    public List<Role> gettole(String jobnum);

    /**
     * 获得对应role下的permission
     * @return permission对象列表
     */
    @Select("SELECT p.id,p.pattern,p.p_name,p.p_describe from role as r\n" +
            "LEFT JOIN role_permission as rp ON rp.role_id = r.id\n" +
            "LEFT JOIN permission as p on rp.permission_id = p.id\n" +
            "where r.id = #{roleid} ")
    public List<Permission> Role2Permission(Integer roleid);

    /**
     * 获取全部role信息
     * @return List<Role>
     */
    @Select("select * from role")
    public List<Role> getAllr();
}
